package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 部门业务层
 * @author GY
 * @version V1.0
 * @date 2025-01-08 17:29
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    /**
     * 查询
     */
    @Override
    public List<Dept> queryAll() {
        return deptMapper.queryAll();
    }

    /**
     * 删除
     */
    @Override
    public void delete(Integer id) {
        deptMapper.delete(id);
    }

    /**
     * 新增部门
     */
    @Override
    public void insert(Dept dept) {
        //手动补全实体属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    /**
     *根据ID查询
     */
    @Override
    public Dept queryById(Integer id) {
        return deptMapper.queryById(id);
    }

    /**
     * 修改
     */
    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }

}
